package model.mchoice;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * Date: Sep 26, 2009
 * Time: 2:25:39 PM
 * @author Jose Martin Rozanec;
 */
public class OposicionMCItemSet implements Serializable {
    private List<OposicionMCItem> mcItems;
    private int pointer;

    public OposicionMCItemSet() {
        mcItems = new ArrayList<OposicionMCItem>();
    }

    public void addMCItem(OposicionMCItem newItem) {
        mcItems.add(newItem);
    }

    public List<OposicionMCItem> getMCItems() {
        return mcItems;
    }

    /**
     * Returns next question. If reaches the end, the first element is returned (circular shift);
     *
     * @return
     */
    public OposicionMCItem next() {
        pointer++;
        if (pointer >= mcItems.size()) {
            pointer=0;
        }
        return mcItems.get(pointer);

    }

    /**
     * Returns current exercise;
     *
     * @return
     */
    public OposicionMCItem current() {
        return mcItems.get(pointer);
    }

    /**
     * Returns previous excercise. If reaches the first element and you ask for the previous one,
     * returns the last one (circular shift);
     *
     * @return
     */
    public OposicionMCItem previous() {
        pointer--;
        if (pointer < 0) {
            pointer=mcItems.size()-1;
        }
        return mcItems.get(pointer);
    }

    public int getCurrentQuestion() {
        return pointer + 1;
    }

    public int getTotalQuestions() {
        return mcItems.size();
    }

    public String toString() {
        StringBuffer buffer = new StringBuffer();
        for (int j = 0; j < mcItems.size(); j++) {
            buffer.append("" + (j + 1) + "- " + mcItems.get(j).toString() + "\n");
        }
        return buffer.toString();
    }

    public int getPuntuation() {
        int puntuation = 0;
        for (int j = 0; j < mcItems.size(); j++) {
            puntuation = puntuation + mcItems.get(j).getCorrectPunctuation();
        }
        return puntuation;
    }

    public OposicionMCItemSet getDefaultSet() {
        OposicionMCItemSet oposicionMCItemSet = new OposicionMCItemSet();
        for (int j = 0; j < mcItems.size(); j++) {
            oposicionMCItemSet.addMCItem(mcItems.get(j).getDefaultClone());
        }
        return oposicionMCItemSet;
    }
}
